(function() {
    var Router = function() {
        this.routes = {}; //用来保存路由
        this.curUrl = ''; //获取当前的hash
    }
    Router.prototype.init = function() { //监听路由变化
        window.addEventListener('hashchange', this.reloadPage.bind(this));
    }
    Router.prototype.reloadPage = function() {
        this.curUrl = location.hash.substring(1) || '/';
        this.routes[this.curUrl]();
    }
    Router.prototype.map = function(key, callback) { //保存路由对应的函数
        this.routes[key] = callback;
    }
    window.Router = Router;
})();